package ink.lovejinhu.leetcode;

import java.util.ArrayList;

/**
 * @Author: jin
 * @Date: 2021/9/6 18:01
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0860 {
    /**
     * 柠檬水找零
     * 是否可以找零
     *
     * @param bills
     * @return
     */
    public boolean lemonadeChange(int[] bills) {
        ArrayList<Integer> five = new ArrayList<>();
        ArrayList<Integer> ten = new ArrayList<>();
        for (int i = 0; i < bills.length; i++) {
            if (bills[i] == 5) {   //不需要找零
                five.add(5);
            } else if (bills[i] == 10) {
                if (five.size() > 0) {
                    ten.add(10);
                    five.remove(0);  //删除
                } else {
                    return false;
                }
            } else {
                //优先减10块
                if (ten.size() > 0) {
                    if (five.size() > 0) {
                        ten.remove(0);
                        five.remove(0);
                    } else {
                        return false;
                    }
                } else {
                    if (five.size() > 3) {
                        five.remove(0);
                        five.remove(0);
                        five.remove(0);
                    } else {
                        return false;
                    }

                }


            }

        }
        return true;
    }

    public static void main(String[] args) {
        ArrayList<Integer> integers = new ArrayList<>();
        integers.add(1);
        integers.add(2);
        integers.add(3);
        integers.add(4);
        integers.remove(0);
        integers.remove(0);
        System.out.println(integers);
    }
}
